package com.example.myyiyanmengjava.http;

import android.util.Log;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class BaseInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Request.Builder requstBuilder = request.newBuilder();

        FormBody.Builder formBuilder = new FormBody.Builder();
        if(request.body() instanceof FormBody){
            FormBody body = (FormBody) request.body();
            for (int i = 0; i < body.size(); i++) {
                formBuilder.addEncoded(body.encodedName(i), body.encodedValue(i));
                Log.e("TAG", "黄: "+body.encodedName(i)+body.encodedValue(i));
            }

            formBuilder
                    .add("operaVersion", "5.1.1")
                    .add("s_screen_width", "900")
                    .add("token","a5FAGSxbJqvA6bwLwQE0HzR4F5KdbPXt-lefy0hRklIoA94IuaDk91rARfdNDdwN-TZp7di58nEHSLEQXCVbmQ==")
                    .add("s_distinct_id", "3880924")
                    .add("app_name", "zgzf")
                    .add("user_token", "a5FAGSxbJqvA6bwLwQE0HzR4F5KdbPXt-lefy0hRklIoA94IuaDk91rARfdNDdwN-TZp7di58nEHSLEQXCVbmQ==")
                    .add("s_manufacturer", "vivo")
                    .add("s_carrier", "CHINA MOBILE")
                    .add("appVersion", "4.5.8.9")
                    .add("imei", "865166024688254")
                    .add("s_ip", "172.16.2.15")
                    .add("s_wifi", "true")
                    .add("platform_type", "4")
                    .add("s_app_version", "4.5.8.9")
                    .add("s_os", "Android")
                    .add("appName", "zgzf")
                    .add("platformType", "4")
                    .add("user_type", "C端用户")
                    .add("ip", "172.16.2.15")
                    .add("device_only_id", "ffffffff-d0a5-d5ef-ffff-ffffc2286e31")
                    .add("appSignatures", "893daee49856e6e0c4661f53919198c3")
                    .add("s_os_version", "5.1.1")
                    .add("device_from", "4")
                    .add("s_screen_height", "1600")
                    .add("s_model", "vivo x5s l");

            FormBody build = formBuilder.build();
            for (int i = 0; i < build.size(); i++) {
                Log.e("TAG", "黄: "+build.name(i)+"="+build.value(i) );
            }
            requstBuilder.post(build);

        }
        return chain.proceed(requstBuilder.build());
    }
}
